<template>
  <div>
    <el-table
      :data="cateList"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="分类编号"> </el-table-column>
      <el-table-column prop="catename" label="分类名称"> </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
          <div>
            <img :src="$pre + scope.row.img" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="success" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="danger" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
          <template slot-scope="scope">
              <div>
                  <el-button type="primary" plain @click="edit(scope.row.id)">编 辑</el-button>
                  <v-del @del="del(scope.row.id)"></v-del>
              </div>
          </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {successAlert,warningAlert} from "../../../util/alert"
import {cateDel} from "../../../request/api"
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
        cateList:"cate/list"
    }),
  },
  methods: {
    ...mapActions({
        reqCateList:"cate/reqChangeList"
    }),
    // 封装版本删除
    del(id){
        cateDel({id:id}).then(res=>{
            if(res.data.code==200){
                // 删除成功弹窗
                successAlert(res.data.msg)
                // 重新请求列表数据
                this.reqCateList()
            }else{
                warningAlert(res.data.msg)
            }
        })
    },
    // 编辑
    edit(id){
        this.$emit("edit",id)
    }
  },
  mounted() {
      this.reqCateList()
  },
};
</script>
<style scoped>
img{
    width: 50px;
    height: 50px;
}
</style>